<?php
/**
 * Created by JetBrains PhpStorm.
 * User: CAIXUDONG
 * Date: 11-6-16
 * Time: 下午4:06
 */
 
include '../bootstrap.php';

$_user = Model::getInstance('user');
$user_info = $_user->needLogin();

$role_ids = $_input->post('role_ids');
$user_id = $_input->post('user_id');

if(!$role_ids){
    $data = array(
        "statusCode"=>"300",
        "message"=>"至少选择一个角色！",
    );
    echo Response::JSON($data);
    exit;
}

Model::getInstance('userhasrole')->delByUserId($user_id);
if($role_ids){
    $role_ids = array_unique($role_ids);
    foreach($role_ids as $v){
        if($v){
            Model::getInstance('userhasrole')->add($user_id,$v);
        }
    }
}

$data = array(
    "statusCode"=>"200",
    "message"=>"角色设置成功!",
);
echo Response::JSON($data);